]> git.openstreetmap.org Git - rails.git/blob - vendor/plugins/rails-i18n/tools/Rails I18n.tmbundle/Support/lib/yaml_waml.rb
First stage of i18n. Some migrations and extra plugins.
[rails.git] / vendor / plugins / rails-i18n / tools / Rails I18n.tmbundle / Support / lib / yaml_waml.rb
1 # stolen from Kakutani Shintaro http://github.com/kakutani/yaml_waml
2
3 require "yaml"
4
5 class String
6   def is_binary_data?
7     false
8   end
9 end
10
11 module YamlWaml
12   def decode(orig_yamled)
13     yamled_str = case orig_yamled
14                  when String then orig_yamled
15                  when StringIO then orig_yamled.string
16                  else return orig_yamled
17                  end
18     yamled_str.gsub!(/\\x(\w{2})/){[$1].pack("H2")}
19     return yamled_str
20   end
21   module_function :decode
22 end
23
24 ObjectSpace.each_object(Class) do |klass|
25   klass.class_eval do
26     if method_defined?(:to_yaml) && !method_defined?(:to_yaml_with_decode)
27       def to_yaml_with_decode(*args)
28         io = args.shift if IO === args.first
29         yamled_str = YamlWaml.decode(to_yaml_without_decode(*args))
30         io.write(yamled_str) if io
31         return yamled_str
32       end
33       alias_method :to_yaml_without_decode, :to_yaml
34       alias_method :to_yaml, :to_yaml_with_decode
35     end
36   end
37 end